package com.hntky.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hntky.common.Result;
import com.hntky.entity.Nurse;
import com.hntky.service.NurseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 周宇轩
 * @date 2023/5/15 17:50
 */
@RestController
@RequestMapping("/nurse")
public class NurseController {

    @Resource
    private NurseService service;

    @GetMapping("/")
    public Result all() {
        return Result.success(service.list());
    }

    /**
     * 分页查询护士
     * @param pageNum
     * @param pageSize
     * @param nname
     * @return
     */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestParam(defaultValue = "") String nname) {
        return Result.success(service.findPage(new Page<Nurse>(pageNum, pageSize), nname));
    }

    /**
     * 新增和修改
     * @param nurse
     * @return
     */
    @PostMapping("/add")
    public Result addAndUpdate(@RequestBody Nurse nurse) {
        return Result.success(service.saveOrUpdate(nurse));
    }

    /**
     * 查询房间
     * @param nid
     * @return
     */
    @PostMapping("/rooms/{nid}")
    public Result selectRooms(@PathVariable Integer nid) {
        return Result.success(service.selectRooms(nid));
    }

    /**
     * 根据id删除
     * @param nid
     * @return
     */
    @GetMapping("/{nid}")
    public Result del(@PathVariable Integer nid) {
        return Result.success(service.removeById(nid));
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("/del/batch")
    public Result delBatch(@RequestBody List<Integer> ids) {
        return Result.success(service.removeBatchByIds(ids));
    }

}
